package com.dongdong.controller;

import com.dongdong.em.Result;
import com.dongdong.model.TbContent;
import com.dongdong.service.ContentService;
import com.dongdong.vo.ContentVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("content")
@RefreshScope        //热更新
public class ContentController {

    @Autowired
    private ContentService contentService;

    @PostMapping("getContentList")
    public Result getContentList(){
        List<ContentVO> volist = contentService.getContentList();
        return Result.OK().setData(volist);
    }

    @GetMapping("toUpdategetById")
    public Result toUpdategetById(@RequestParam Long id){
        TbContent content = contentService.toUpdategetById(id);
        return Result.OK().setData(content);
    }

    @PostMapping("InsertContent")
    public Result InsertContent(@RequestBody ContentVO contentVO){
        int i = contentService.InsertContent(contentVO);
        if (i <= 0){
            return Result.ERROR();
        }
        return Result.OK();
    }

    @DeleteMapping("deleteContent/{arr}")
    public Result deleteContent(@PathVariable Long[] arr){
        int i = contentService.deleteContent(arr);
        if (i <= 0){
            return Result.ERROR();
        }
        return Result.OK();
    }


    //查询首页广告轮播图 根据内容类目ID 查询全部
    @GetMapping("getContentByCateGoryId")
    public Result getContentByCateGoryId(@RequestParam Long categoryId){
        List<ContentVO> contentvolist = contentService.getContentByCateGoryId(categoryId);
        return Result.OK().setData(contentvolist);
    }
}
